package com.useeinfo.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.useeinfo.module.Member;
import com.useeinfo.service.IMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by xianping on 2017/1/20.
 */
@Controller
@RequestMapping("/web/member")
public class MemberAction {

    @Autowired
    private IMember memberService;

    @RequestMapping(value = "/findMembers",produces ="text/html;charset=UTF-8")
    @ResponseBody
    public String findMembers(){
        System.out.println("--------------findMembers    start---------------");
        List<Member> memberList = memberService.findMembers();
        String str = JSON.toJSONString(memberList);
        JSONArray jsonArray = JSON.parseArray(str);

        JSONObject jsonObject = new JSONObject();
		jsonObject.put("errorCode","0");
		jsonObject.put("errorMsg","成功");
        jsonObject.put("total",memberList.size());
        jsonObject.put("rows",jsonArray);

        System.out.println("response string:"+jsonObject.toJSONString());
        System.out.println("--------------findMembers    end---------------");
        return jsonObject.toJSONString();
    }
}
